package leader.action;
import java.util.ArrayList;
import java.util.List;

import leader.service.DirectTeacherService;
import leader.service.DirectTreatiseService;
import leader.service.LeaderService;
import leader.tool.JTableDefine;
import teacher.bean.Teacher;
import teacher.bean.Treatise;
import tools.StringDate;

import com.opensymphony.xwork2.ActionContext;


public class DirectTreatisePrintAction {
	private int flags;
	private String datedown;
	private String dateup;
	private String treName;
	private int flag;
	

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public int getFlags() {
		return flags;
	}

	public void setFlags(int flags) {
		this.flags = flags;
	}

	public String getDatedown() {
		return datedown;
	}

	public void setDatedown(String datedown) {
		this.datedown = datedown;
	}

	public String getDateup() {
		return dateup;
	}

	public void setDateup(String dateup) {
		this.dateup = dateup;
	}

	public String getTreName() {
		return treName;
	}

	public void setTreName(String treName) {
		this.treName = treName;
	}

	public String execute() {
		System.out.println("********************"+flag);
		Teacher lea=(Teacher) ActionContext.getContext().getSession().get("leader");
		DirectTeacherService DT = new DirectTeacherService();
		List<Treatise> lists = new ArrayList<Treatise>();
		DirectTreatiseService DS = new DirectTreatiseService();
		System.out.println("========="+flag);
		if(0 == flag) {
			lists = DS.selectAllDirectTreatise(lea);
		}
		if(1 == flag) {
			StringDate date = new StringDate();
			lists = DS.selectDirectTreatiseByTime(date.StringToDate(datedown),date.StringToDate(dateup), lea);
		}
		if(2 == flag) {
			lists = DS.selectTreatiseLikeName(treName, lea);
		}
		if(3 == flag) {
			Treatise tre = new Treatise();
			tre.setState(0);
			lists = DS.selectDirectTreatiseByState(lea, tre);
		}
		
		System.out.println(lists.size());
		String[][] columnNames = new String[lists.size()+1][7];
		
		columnNames[0] = new String[]{"编号","名称","作者","通讯作者","出版日期","出版社","概念"};
		for(int i=1;i<=lists.size();i++) {
			Treatise treatise = lists.get(i-1);
			columnNames[i][0] = String.valueOf(i);
			columnNames[i][1] = treatise.getName();
			columnNames[i][2] = treatise.getAuthor();
			Teacher tea = new Teacher();
			tea.setTeaId(treatise.getTeaId());			
			columnNames[i][3] = DT.selectTeacherById(tea).getName();
			StringDate date = new StringDate();
			columnNames[i][4] = date.DateToString(treatise.getDate());
			columnNames[i][5] = treatise.getPress();
			columnNames[i][6] = treatise.getAbstract_();
		}
		int[] px = new int[]{40,120,50,50,80,80,105};
		JTableDefine d = new JTableDefine();
		d.printTable(columnNames,px);
		System.out.println("============================");
		return "success";
	}
}
